package com.lemon.smartsafety.ui.activity.fire;

import android.os.Bundle;
import android.support.design.widget.AppBarLayout;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lemon.smartsafety.R;
import com.lemon.smartsafety.file.MySPUtilsName;
import com.lemon.smartsafety.http.HttpPath;
import com.lemon.smartsafetynew.ui.activity.base.NewBaseActivity;
import com.lemon.smartsafety.utils.CommonUtil;
import com.lemon.smartsafety.utils.LogUtils;
import com.lemon.smartsafety.utils.SystemUtil;
import com.lemon.smartsafety.utils.app.ToastUtil;
import com.rengwuxian.materialedittext.MaterialEditText;

import butterknife.Bind;
import butterknife.OnClick;

public class SettingFireUrlActivity extends NewBaseActivity {

    @Bind(R.id.main_title)
    TextView mainTitle;
    @Bind(R.id.toolbar)
    Toolbar toolbar;
    @Bind(R.id.app_bar_layout)
    AppBarLayout appBarLayout;
    @Bind(R.id.editFileUrl)
    MaterialEditText editFileUrl;
    @Bind(R.id.btnSubmit)
    Button btnSubmit;
    @Bind(R.id.mainContainer)
    LinearLayout mainContainer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void getBundleArgs() {

    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_setting_fire_url;
    }

    @Override
    protected void initTitleView() {
        setBarTitle("消防服务器设置");
    }

    @Override
    protected void initView() {

        String strHttpBasePath="";
        if(!CommonUtil.strIsEmpty(MySPUtilsName.getSP(MySPUtilsName.TEST_HTTPATH,"").toString()))
        {
            strHttpBasePath= MySPUtilsName.getSP(MySPUtilsName.TEST_HTTPATH,"").toString();
        }
        else{
            strHttpBasePath= HttpPath.Base;
        }
        LogUtils.LOGE("原服务器地址："+strHttpBasePath);
        editFileUrl.setText(strHttpBasePath);

    }

    @Override
    protected void initHttp() {

    }

    @Override
    protected void initList() {

    }

    @Override
    protected void loadList() {

    }

    @Override
    protected void refreshView() {

    }

    @Override
    protected void callFinish() {
         mActivity.finish();
    }


    @OnClick({R.id.btnSubmit})
    public void onButtonClick(View v) {
        switch (v.getId()) {
            case R.id.btnSubmit:
                try {
                    SystemUtil.HideKeyboard(mActivity);
                    if(CommonUtil.strIsEmpty(editFileUrl.getText().toString().trim())){
                        ToastUtil.show("服务器地址不能为空");
                        return;
                    }
                    LogUtils.LOGE("修改后服务器地址："+editFileUrl.getText().toString().trim());
                    MySPUtilsName.saveSP(MySPUtilsName.TEST_HTTPATH,editFileUrl.getText().toString().trim());
                    ToastUtil.show("服务器地址修改成功");
                    callFinish();
                } catch (Exception e) {
                    e.printStackTrace();
                }
                break;
            default:
                break;
        }
    }





}
